<?php
    class News_Product_Model extends CI_Model
    {
        var $table = "db_news_product";
        public function __construct()
        {
            parent::__construct();
        }
        public function update_news_product($id,$data)
        {
            $this->db->where('id_news_product',$id);
            $data = array(
                'title' =>$data['title'],
                'author'=>$data['author'],
                'date_post'=>$data['date_post'],
                'body'    =>$data['body'],
                'image'   =>$data['image'],
				'image_thumb' =>$data['image_thumb'],
                'active'  =>$data['active'],
                'order_news_product'   =>$data['order_news_product'],
                'id_news' =>$data['id_news'],
                'url'     =>$data['url'],                
                'meta_keyword' =>$data['meta_keyword'],
                'meta_description' =>$data['meta_description'],
                'tags' =>$data['tags'],
				'vitri_show' =>$data['vitri_show'],
				'title_short' =>$data['title_short']                                            
            );
            $this->db->set($data);
            if($this->db->update($this->table)) return true; else return false;
            
        }
		public function add_news_product($data)
        {
            
            $data = array(
                'title' =>$data['title'],
                'author'=>$data['author'],
                'date_post'=>$data['date_post'],
                'body'    =>$data['body'],
                'image'   =>$data['image'],
				'image_thumb' =>$data['image_thumb'],
                'active'  =>$data['active'],
                'order_news_product'   =>$data['order_news_product'],
                'id_news' =>$data['id_news'],
                'url'     =>$data['url'],                
                'meta_keyword' =>$data['meta_keyword'],
                'meta_description' =>$data['meta_description'],
                'tags' =>$data['tags'],
				'vitri_show' =>$data['vitri_show'],
				'title_short' =>$data['title_short']                                  
            );
            $this->db->set($data);
            if($this->db->insert($this->table)) return true; else return false;
        }
        public function get_id($id)
        {
            $this->db->where("id_news_product",$id);
            return $this->db->get($this->table)->row();           
        }
		 public function show()
        {
            return $this->db->get($this->table)->result();            
        }
        public function delete_id($id)
        {
			$this->db->where("id_news_product",$id);
            return $this->db->delete($this->table);
        }
        function change_update_active($id,$data)
        {
            $this->db->where('id_news_product',$id);
            $data = array(
            'active' => $data['active']
            );
            $this->db->set($data);
            if($this->db->update($this->table)) return true; else return false;
        }    
         function total($dk = null)
		{
			if($dk != null)
			{
				$this->db->where('id_news_product', $dk);
			}
			
			
			
			return $this->db->count_all_results($this->table);
		}
        function news_product_phantrang($begin,$max)
		{
			if($begin == ''){
				$begin = 0;
			}
			if($max >= 0 && $max != ''){
				$limit = 'limit '.$begin.','. $max;
			}else{
				$limit ='';	
			}
            
		return $this->db->query('select * from db_news_product  order by id_news_product '. $limit)->result();	
		}
    }
?>